<template>
  <div class="idadd">
    <el-dialog
      :title="info ? '编辑' : '新增'"
      :visible.sync="dialogVisible"
      width="25%"
    >
      <div class="cadade">
        角色名称<el-input
          v-model="PmsBrand.roleName"
          placeholder="角色名称"
        ></el-input>
      </div>

      <div class="cadade">
        角色编码<el-input
          v-model="PmsBrand.roleCode"
          placeholder="角色编码"
        ></el-input>
      </div>
      <div class="cadade">
        角色描述<el-input
          v-model="PmsBrand.remark"
          placeholder="角色描述"
        ></el-input>
      </div>

      <div>
        <el-tree
          :data="data"
          show-checkbox
          node-key="id"
          :default-expanded-keys="[2, 3]"
          :default-checked-keys="[5]"
          :props="defaultProps"
        >
        </el-tree>
      </div>

      <span slot="footer" class="footers">
        <el-button @click="cancle">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import authority from '@/api/authority'
import mixins from '@/mixins'
export default {
  mixins: [mixins],
  data() {
    return {
      info: '',
      dialogVisible: false,
      defaultProps: {
        children: 'children',
        label: 'title',
      },
      PmsBrand: {
        // id: '',
        // nickName: '', //用户昵称
        // password: '', //密码
        // // roleIds: '',
        // salt: '',
        // username: '', //用户名
        remark: '', //角色描述
        roleCode: '', //角色编码
        roleName: '', //角色名称
      },
      data: [],
    }
  },
  created() {},
  mounted() {},
  methods: {
    submit() {
      this.dialogVisible = false

      if (this.info) {
        authority
          .updateRolePermissions({
            id: this.info.id,
            roleName: this.PmsBrand.roleName,
            roleCode: this.PmsBrand.roleCode,
            remark: this.PmsBrand.remark,
          })
          .then(res => {
            console.log(res, '编辑')
            this.$parent.findUsersByPage()
          })
      } else {
        authority
          .saveRolePermissionsApi({
            // id: '',
            roleName: this.PmsBrand.roleName,
            roleCode: this.PmsBrand.roleCode,
            remark: this.PmsBrand.remark,
          })
          .then(res => {
            console.log(res, 'res')
            this.$parent.findUsersByPage()
          })
      }
      this.PmsBrand = ''
    },
    cancle() {
      this.dialogVisible = false
      this.PmsBrand = ''
    },
    //子组件的打开方法
    open(data) {
      this.dialogVisible = true

      if (data) {
        console.log(data, 'data')

        this.PmsBrand = data
        // this.PmsBrand.nickName = data.nick_name
        this.info = data
        console.log(this.info, 'this.info')
      } else {
        this.info = ''
      }
      authority.getInitMenusApi().then(res => {
        this.data = res.data.permissionList
        console.log(this.data, 'resssssss')
      })
    },
  },
}
</script>

<style scoped lang="scss">
.idadd ::v-deep .el-dialog {
  height: 500px !important;
}
.cadade {
  margin-bottom: 10px;
}
.el-input {
  width: 300px;
}

.footers {
  position: absolute !important;
  bottom: 10px !important;
  right: 10px;
}
.switchsed {
  position: absolute;
  top: 250px;
  left: 120px;
}
.switchses {
  position: absolute;
  top: 250px;
  left: 620px;
}
</style>